home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / text / hyper / gmake.lha / gmake / c_source / main.c < prev    next >
C/C++ Source or Header  |  1995-08-22  |  5KB  |  263 lines

  1. //    Program        Amiga Guide Compiler
  2. //    Author        Gary Greenhill
  3.  
  4. #include "main.h"
  5. #include "info.h"
  6.  
  7. // Main entry point.. no wbmain()
  8. main()
  9.  {
  10.  
  11.   // Initialisation proceedures
  12.   initialise_values();
  13.   command_line_intput();
  14.   initialise_debug(debug);
  15.   
  16.   // Attempt to open the GMAKEFILE
  17.   if (open_gmakefile(gmakefile))
  18.     {
  19.     REM ("GMAKEFILE open");
  20.     getdata_gmakefile();
  21.     check_guidefile();    
  22.  
  23.     if (open_guidefile())
  24.      {
  25.         REM ("GUIDEFILE open");
  26.         init_guidefile();
  27.         set_pagelist();
  28.         my_type++;
  29.         node_main();
  30.         node_standard();
  31.         node_pages();
  32.         REM ("Done!");
  33.      }
  34.     }
  35.  
  36.   // shutdown procedures
  37.  
  38.   shut_down();
  39.  }
  40.  
  41. copy_node(char * node)
  42.  {
  43.   if(open_file(node))
  44.     {
  45.      file_to_guide();
  46.      close_file();
  47.     }
  48.  }
  49.  
  50. node_pages()
  51.  {
  52.     int num,max,page;
  53.     MTEXT filename;
  54.     MTEXT nodename;
  55.     MTEXT nodedesc;
  56.     REM("Begining PAGE nodes");
  57.  
  58.     max = page_num();
  59.  
  60.     for(num = max,page=1; num >0;num--)
  61.      {
  62.         MTEXT text;
  63.         sprintf(nodename,"PAGE%d", page);
  64.         strcpy (filename,page_file(num));
  65.         strcpy (nodedesc, get_nodedesc());
  66.         NOTE("Page node: ", nodedesc);
  67.         sprintf(text,"@node %s \"%s\"",
  68.                         nodename, nodedesc);
  69.                 txt_to_guide(text);
  70.  
  71.                 sprintf(text,"@prev %s",last_node_name);
  72.                 txt_to_guide(text);
  73.  
  74.                 copy_node(filename);
  75.  
  76.         page++;
  77.         if(page < max)
  78.          {
  79.           MTEXT next;
  80.           sprintf(next,"@next PAGE%d", page);
  81.          }
  82.         txt_to_guide("@endnode");
  83.         strcpy(last_node_name,nodename);
  84.      }
  85.  }
  86.  
  87. node_standard()
  88.  {
  89.     MTEXT text;
  90.     while(my_type != PAGE)
  91.      {
  92.         MTEXT filename;
  93.         MTEXT nodename;
  94.         MTEXT nodedesc;
  95.  
  96.         strcpy (filename, getfilename(my_type));
  97.         strcpy (nodename, txt_type(my_type));
  98.         strcpy (nodedesc, get_nodedesc());
  99.  
  100.         NOTE("Standard node: ", nodedesc);
  101.         sprintf(text,"@node %s \"%s\"",
  102.             nodename, nodedesc);
  103.         txt_to_guide(text);
  104.  
  105.         sprintf(text,"@prev %s",last_node_name);
  106.         txt_to_guide(text);
  107.  
  108.         copy_node(filename);
  109.         my_type++;
  110.         if(find_node())
  111.                     {
  112.                     MTEXT next;
  113.                     strcpy(next,"@next ");
  114.                     strcat(next,txt_type(my_type));
  115.                     txt_to_guide(next);
  116.                     }
  117.         else if(my_type == PAGE)
  118.             {
  119.             if (exist_type(PAGE))
  120.                 {
  121.                                txt_to_guide("@next PAGE1"); 
  122.                 }
  123.             }                
  124.             txt_to_guide("@endnode");
  125.         strcpy(last_node_name,nodename);
  126.      }
  127.  }
  128.  
  129. node_midmain()
  130.  {
  131.    int index = 1;
  132.    FileType ft;
  133.    int max,num,page;
  134.  
  135.    ft = POST;
  136.    ft++;
  137.  
  138.        REM ("Index standard files");
  139.     txt_to_guide("\n\tContents");
  140.     while(ft != PAGE)
  141.         {
  142.          if(exist_type(ft))
  143.           {
  144.            MTEXT nodename;
  145.            MTEXT nodedesc;
  146.            MTEXT text;
  147.            getfilename(ft); // Needed to get the correct descip.
  148.            strcpy (nodename, txt_type(ft));
  149.            strcpy (nodedesc, get_nodedesc());
  150.  
  151.            NOTE("Adding contents node: ", nodename);
  152.            sprintf(text, "\t%d\t@\{\"%s%s\" link %s\}",
  153.                 index, nodedesc,
  154.                 space_control(nodedesc), nodename);
  155.            index++;  txt_to_guide(text);
  156.  
  157.           }
  158.          ft++;
  159.         }
  160.  
  161.       REM("Index page files");
  162.  
  163.       max = page_num();
  164.       for(num = max,page=1; num >0;num--)
  165.         {
  166.            MTEXT nodename;
  167.            MTEXT nodedesc;
  168.            MTEXT text;
  169.             
  170.            sprintf(nodename,"PAGE%d", page);
  171.                    page_file(num);  // To get the correct desc
  172.                    strcpy (nodedesc, get_nodedesc());
  173.  
  174.            sprintf(text, "\t%d\t@\{\"%s%s\" link %s\}",
  175.                                 index, nodedesc,
  176.                 space_control(nodedesc), nodename);
  177.                    index++;page++;  txt_to_guide(text);
  178.          }
  179.  
  180.  
  181.       REM("End Contents");
  182.       txt_to_guide("\n");
  183.  }
  184.  
  185.  
  186.  
  187. node_main()
  188.  {
  189.   MTEXT pre;
  190.   MTEXT post;
  191.  
  192.   REM ("Begining MAIN section");
  193.     txt_to_guide("@node MAIN \"Introduction\"");
  194.  
  195.   REM ("MAIN pre section");
  196.     strcpy(pre,getfilename(PRE));
  197.     copy_node(pre);
  198.     my_type++;
  199.  
  200.   REM ("MAIN mid section");
  201.     node_midmain();
  202.  
  203.   REM ("MAIN post section");
  204.     strcpy(post,getfilename(POST));
  205.     copy_node(post);
  206.     my_type++;    
  207.  
  208.   REM ("Ending MAIN section");
  209.     if(find_node())
  210.         {
  211.         MTEXT next;
  212.         strcpy(next,"@next ");
  213.         strcat(next,txt_type(my_type));
  214.         txt_to_guide(next);
  215.         }
  216.     txt_to_guide("@endnode");
  217.     strcpy(last_node_name,"MAIN");
  218.  } 
  219.  
  220. BOOL find_node()
  221.  {
  222.  
  223.     while(my_type < PAGE)
  224.         {
  225.          if(exist_type(my_type))
  226.             return TRUE;
  227.          my_type++;
  228.         }
  229.     return FALSE;
  230.  }
  231.  
  232.  
  233. // Close Down stuff
  234. shut_down()
  235. {
  236.   dwait();
  237.   printf("Finished!\n");
  238.   close_files();
  239.   close_debug();
  240. }
  241.  
  242.  
  243. // Initial values
  244. initialise_values()
  245. {
  246. init_typearray();
  247. strcpy(gmakefile,"gmakefile");
  248. my_type=GUIDE;
  249. }
  250.  
  251.  
  252. // Read in the command line input;
  253. command_line_intput()
  254. {
  255. rda = ReadArgs(ArgStr, ArgArray, rda);
  256.  
  257. if (ArgArray[0])
  258.     strcpy(gmakefile,ArgArray[0]);
  259. if (ArgArray[1])
  260.     debug = TRUE;
  261. FreeArgs(rda);
  262. }
  263.